package com.wanxi.treeset;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

public class TeacherAgrConstructorTest {
    public static void main(String[] args) {
//        Set<Teacher>  set=new TreeSet<>(new Comparator<Teacher>() {
//            @Override
//            public int compare(Teacher o1, Teacher o2) {
//                int res = o1.getAge() - o2.getAge();
//                return res == 0 ? o1.getName().compareTo(o2.getName()) : res;
//            }
//        });
        Set<Teacher> set=new TreeSet<>((o1, o2) -> {
            int res = o1.getAge() - o2.getAge();
            return res == 0 ? o1.getName().compareTo(o2.getName()) : res;
        });
        set.add(new Teacher("zhangsan", 11));
        set.add(new Teacher("lisi", 13));
        set.add(new Teacher("wangwu", 17));
        set.add(new Teacher("lucyb", 14));
        System.out.println(set);
    }
}
